<?php
/**
 * Created by PhpStorm.
 * User: chenxiongde
 * Date: 17/4/30
 * Time: 下午3:19
 */
function  p($var){
    if(is_bool($var) || is_null($var)){
      var_dump($var);
    }else{
        echo '<pre style="padding:10px;margin:10px;border:2px solid #ccc;font-size:18px;font-weight:700;">';
        print_r($var);
        echo '</pre>';
    }

}

function   config($var=null,$val=null){
    static  $config = array();
    if(is_array($var)){
        $config = array_merge($config,array_change_key_case($var,CASE_UPPER));
        return ;
    }
    if(is_string($var)){
        if(!is_null($val)){
            $config[$var] = $val;
        }
        return isset($config[$var])?$config[$var]:null;
    }
    if(is_null($var)&&is_null($val)){
        return $config;
    }
}

function  go($url,$time=0,$msg=''){
    if(!headers_sent()){
        ($time == 0) ?header('Location:'.$url):header("refresh:{$time},url={$url}");
        die($msg);
    }else{
        echo "<meta http-equiv='refresh' content='{$time}' url='{$url}'>";
        if($time)  die($msg);
    }
}


function  halt($error,$level=3,$type='',$dist=''){
    if(is_array($error)){
        Log::write($error['message'],$level,$type,$dist);
    }else{
        Log::write($error,$level,$type,$dist);
    }
    $e=array();
    if(DEBUG){
        if(!is_array($error)){
            $trace = debug_backtrace();
            $e['message']=$error;
            $e['file'] = $trace[0]['file'];
            $e['line'] = $trace[0]['line'];
            $e['class'] = isset($trace[0]['class'])?$trace[0]['class']:'';
            $e['function'] = isset($trace[0]['function'])?$trace[0]['function']:'';
            ob_start();
            debug_print_backtrace();
            $e['trace'] = htmlspecialchars(ob_get_clean());
        }else{
            $e = $error;
        }
    }else{

    }
}
?>